
const expressionData = (function () {
    let base = (function () {
        let b = []

        // A-Z
        for (let i = 65; i < 91; i++) {
            b.push(String.fromCharCode(i))
        }
        // a-z
        for (let i = 97; i < 123; i++) {
            b.push(String.fromCharCode(i))
        }
        // 1 - 9
        for (let i = 0; i < 10; i++) {
            b.push(i.toString())
        }

        return b
    })()

    let UUID = (function (base) {
        let UUIDFn = function (num) {
            let result = new Array(num)
            let size = base.length
            let index = 0
            for (let i = 0; i < num; i++) {
                index = Math.floor(Math.random() * size)
                result[i] = base[index]
            }

            return result.join('')
        }
        return UUIDFn
    }(base))

    // 处理数算子
    let expression = {
        // 处理维度
        wd: function (arr) {
            return arr.map((v) => {
                let a = {}
                a.colEn = v.name
                a.columnColor = '#33443322'
                a.columnSharp = null
                a.orderType = 'asc'
                a.sortColName = 'id'
                a.groupType = 'same'
                a.groupId = '1'
                a.showName = v.value
                a.beShow = 'true'
                return a
            })
        },
        // 度量
        dl: function (arr) {
            return arr.map((v) => {
                let a = {}
                a.colEn = v.name
                a.columnColor = '#33443322'
                a.columnSharp = null
                a.totalCalc = 'sum'
                a.fastCalc = 'sum'
                a.dataFormat = 'same'
                a.beShow = 'true'
                a.showName = v.value
                a.beShow = 'true'
                return a
            })
        },
        // 初始化数据
        arr: function (arr) {
            return arr.map((v) => {
                let a = {}
                a.name = v.colEn
                a.value = v.showName
                a.id = UUID(16)
                a.width = 100
                return a
            })
        }
    }

    function ExpressionData () {

    }

    let fn = ExpressionData.prototype

    fn.UUID = UUID

    fn.setData = function (type, arr) {
        return expression[type](arr)
    }

    return new ExpressionData()
})()

export default expressionData
